<?php
class TestClass{
	private $name;
	public function __construct($name){
		$this->name = $name;
	}
	public static function greeting($name){
		return "Hello $name!";
	}
	public function doMoo(){
		echo "alert('Hello " . $this->name . " from an instance method.')";
	}
	public static function getArray(){
		return array(2,4,7);
	}
	private static function secret(){
		// this is not callable from JS, because it's private.
	}
}

function timeFormat($format){
	$format = strftime($format);
	echo "$('result').setHTML('$format')"
		. ".effect('background-color').start('9f9', 'fff');";
}
require "mooremote.php";
$moo = new MooRemote();
// custom function
$moo->registerFunction("timeFormat");
// native function
$moo->registerFunction("md5");
// static class
// can be called from JS with mooRemote.TestClass.getArray(); mooRemote.TestClass.greeting(); etc.
$moo->registerClass('TestClass'); 
// class instances
// can call all static methods plus doMoo with: mooRemote.foo.doMoo();
$moo->registerClass('foo', new TestClass("John"));
// only allow 'doMoo' to be called from JS
// only mooRemote.bar.doMoo(); can be called. All other methods are blocked.
$moo->registerClass('bar', new TestClass("Joe"), array("doMoo"));
$moo->processRequest();

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>MooRemote - Demo</title>
	<link  href="style.css" type="text/css" rel="stylesheet" />
	<script src="mootools.svn.js" type="text/javascript"></script>
	<script src="mooremote.js" type="text/javascript"></script>
	<?php echo $moo->getJavascript(); ?>
	<script type="text/javascript">
		window.addEvent("domready", function(){
			$("timeformat").addEvent("click", function(e){
				e.preventDefault();
				var input = $("input").getValue();
				mooRemote.timeFormat(input);
			});
			$("md5").addEvent("click", function(e){
				e.preventDefault();
				var input = $("input").getValue();
				mooRemote.md5(input).callback(myCallback);
			})
		});
		function myCallback(md5){
			$('result').setHTML(md5);
		};
	</script>
</head>
<body>
	<form action="#">
		<h1>MooRemote</h1>
		<input type="text" id="input" value="%m/%d/%y - %H:%M:%S" />
		<button id="timeformat">strftime</button>
		<button id="md5">MD5</button>

		<p class="last">
			Result: <span id="result">&nbsp;</span>
		</p>
	</form>
	<div class="source">
		<h2>Source</h2>
		<?php highlight_file(__FILE__); ?>
	</div>
</body>
</html>